package cz.gelion.shylock.invoice.entity

import cz.gelion.shylock.invoice.ManagedInfo
import scala.beans.BeanProperty
import javax.persistence.ManyToOne
import javax.persistence.JoinColumn
import javax.persistence.Column
import javax.persistence.Temporal
import javax.persistence.TemporalType
import java.util.Calendar
import javax.persistence.Id
import javax.persistence.GeneratedValue
import javax.persistence.PreUpdate
import javax.persistence.PrePersist
import javax.persistence.Entity
import javax.persistence.Table
import javax.persistence.JoinColumns


@Entity
@Table(name="invoice", schema="invoice")
class Invoice extends ManagedInfo {

  @BeanProperty
  @Id
  @Column(name="id")
  @GeneratedValue
  var id:Int = _
  
  @BeanProperty
  @Column(name="invoiceno")
  var invoiceNo:Int = _
  
  @BeanProperty
  @Column(name="payment_code")
  var paymentCode:String = _
  
  @BeanProperty
  @ManyToOne
  @JoinColumn(name="buyer")
  var buyer:SubjectUnit = _
  
  @BeanProperty
  @ManyToOne
  @JoinColumns(Array(new JoinColumn(name="seller_issuer"), new JoinColumn(name="seller_subject")))
  var issuer:InvoiceManager =_
  
  @BeanProperty
  @Column(name="taxpoint_date")
  @Temporal(TemporalType.DATE)
  var taxpointDate:Calendar = _
  
  @BeanProperty
  @Column(name="payment_date")
  @Temporal(TemporalType.DATE)
  var paymentDate:Calendar = _
  
  @BeanProperty
  @Column(name="issued_date")
  @Temporal(TemporalType.DATE)
  var issuedDate:Calendar = _
  
  @BeanProperty
  @Column(name="total_amount")
  var totalAmount:Float = _
  
  @BeanProperty
  @Column(name="tax_amount")
  var taxAmount:Float = _
  
  
  //TODO: invoice items
  
  
  @BeanProperty
  @ManyToOne
  @JoinColumn(name="muser")
  var manager:Manager = _
  
   
  @BeanProperty
  @Column(name="mtime")
  @Temporal(TemporalType.TIMESTAMP)
  var mtime:Calendar = _
  
  
  @PreUpdate
  @PrePersist
  def update = stamp
  
}